package gunfire.relics;

import basemod.abstracts.CustomRelic;
import com.badlogic.gdx.graphics.Texture;
import com.evacipated.cardcrawl.mod.stslib.relics.ClickableRelic;
import com.megacrit.cardcrawl.actions.common.RelicAboveCreatureAction;
import com.megacrit.cardcrawl.actions.utility.SFXAction;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.helpers.PowerTip;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.relics.AbstractRelic;
import gunfire.GunfireMod;
import gunfire.actions.ElementalEffectAction;
import gunfire.util.TextureLoader;

import static gunfire.GunfireMod.*;

public class ElementalRing extends CustomRelic implements ClickableRelic {

    public static final String ID = GunfireMod.makeID("ElementalRing");
    private static final Texture IMG = TextureLoader.getTexture(makeRelicPath("ElementalRing0.png"));
    private static final Texture OUTLINE = TextureLoader.getTexture(makeRelicOutlinePath("blank.png"));
    public int elementType = 0;

    public ElementalRing() {
        super(ID, IMG, OUTLINE, RelicTier.RARE, LandingSound.CLINK);
        this.elementType = 0;
        this.refreshDescAndImg();
    }

    private void refreshDescAndImg(){
        this.setTextureOutline(TextureLoader.getTexture(makeRelicPath("ElementalRing" + this.elementType + ".png")), OUTLINE);
        this.description = DESCRIPTIONS[this.elementType];
        this.tips.clear();
        this.tips.add(new PowerTip(this.name, this.description));
        this.initializeTips();
    }

    @Override
    public void onRightClick() {
        CardCrawlGame.sound.play("RELIC_DROP_CLINK");
        this.elementType = (this.elementType + 1) % 3;
        this.refreshDescAndImg();
    }

    @Override
    public void atBattleStart() {
        this.flash();
        for (AbstractMonster mo : AbstractDungeon.getCurrRoom().monsters.monsters) {
            if (!mo.isDeadOrEscaped()) {
                if(this.elementType == 0){
                    this.addToBot(new ElementalEffectAction(mo, AbstractDungeon.player, 2, GunfireMod.ElementalEffect.Burning));
                } else if(this.elementType == 1){
                    this.addToBot(new ElementalEffectAction(mo, AbstractDungeon.player, 2, GunfireMod.ElementalEffect.Decay));
                } else {
                    this.addToBot(new ElementalEffectAction(mo, AbstractDungeon.player, 2, GunfireMod.ElementalEffect.Shock));
                }
                this.addToBot(new RelicAboveCreatureAction(mo, this));
            }
        }
    }

    @Override
    public String getUpdatedDescription() {
        return DESCRIPTIONS[this.elementType];
    }

    @Override
    public AbstractRelic makeCopy() {
        return new ElementalRing();
    }
}
